
package CSS::Preprocessor::BufferPos;

use strict;
use Carp qw(croak);
use fields qw(
    buffer_name
    line
    column
    char
);
use overload (
    '""' => sub {$_[0]->as_string},
    '==' => sub {$_[0]->{char} == $_[1]->{char}},
);

sub new {
    my $class = shift;
    my %opts = @_;

    my $self = fields::new($class);

    foreach my $k (qw(buffer_name line column char)) {
        $self->{$k} = delete $opts{$k};
    }

    croak "Unsupported option(s) ".join(',', keys %opts) if %opts;

    return $self;
}

sub buffer_name {
    return $_[0]->{buffer_name};
}

sub line {
    return $_[0]->{line};
}

sub column {
    return $_[0]->{column};
}

sub char {
    return $_[0]->{char};
}

sub as_string {
    my $self = shift;
    return $self->buffer_name." line ".$self->line.", column ".$self->column;
}

1;

